﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace PersonalPictureViewer
{
    public partial class Form1 : Form
    {
        int[] x = new int[500];
        
        int count = 0;
        String[] stx = new String[500];
        String[] stx1 = new String[500];
        String[] stx2 = new String[500];
        String[] stx3 = new String[500];

        int j = 0;


        public Form1()
        {
            InitializeComponent();
            //this.Icon=

        }

        private void button1_Click(object sender, EventArgs e)
        {

            folderBrowserDialog1.ShowDialog();
            textBox1.Text = folderBrowserDialog1.SelectedPath;

            

            
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
            
            label1.Text = "SELECT FOLDER";
            button1.Text = "BROWSE";
            button2.Text = "SHOW CONTENTS";
            label2.Text = "SELECT ITEM";
            button6.Text = "ABOUT US";
            
            comboBox1.Text = "Type";
            comboBox1.Items.Add("JPG ITEMS");
            comboBox1.Items.Add("PNG ITEMS");
            comboBox1.Items.Add("BMP ITEMS");
            comboBox1.Items.Add("JPEG ITEMS");
            comboBox1.Items.Add("ICO ITEMS");
            comboBox1.Items.Add("GIF ITEMS");

            button3.Enabled = false;
            button4.Enabled = false;
            button2.Enabled = false;
            comboBox1.Enabled = false;
            label3.Text = "SELECT FILE TYPE";
            button3.Text = "START SLIDESHOW";
            button4.Text = "STOP SLIDESHOW";
            button5.Text = "HELP";


          


        }

            
            
        

      

        private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
        {

            //nothing in here

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {

                int temp = listBox1.SelectedIndex;
                

                pictureBox1.Image = Image.FromFile(stx[temp]);

            }
            catch(IndexOutOfRangeException excp)
                {
                    MessageBox.Show("Please click on the specific item to preview");
                }
               
            
            }
      
        

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            button3.Enabled = true;
            button4.Enabled = true;
            comboBox1.Enabled = true;
            listBox1.Items.Clear();
          
                string foldername = this.folderBrowserDialog1.SelectedPath;
                int len = foldername.Length;
                len = len + 1;
                j = 0;
                count = 0;


                foreach (string f in Directory.GetFiles(foldername))
                {
                    
                    string result1 = f.Remove(0, len);
                    if (result1.EndsWith(".jpg") || result1.EndsWith(".JPG") || result1.EndsWith(".png") || result1.EndsWith(".PNG") || result1.EndsWith(".bmp") || result1.EndsWith(".BMP") || result1.EndsWith(".ico") || result1.EndsWith(".ICO") || result1.EndsWith(".gif") || result1.EndsWith(".GIF") || result1.EndsWith(".jpeg") || result1.EndsWith(".JPEG"))
                    {

                        stx[j] = f;
                        
                        count++;
                        //MessageBox.Show(stx[j]);
                        j++;


                        this.listBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(result1));
                        //System.IO.Path.GetFileNameWithoutExtension(FileName)


                    }

                }
                if (comboBox1.Text == "JPG ITEMS")
                {
                    listBox1.Items.Clear();

                    //string foldername = this.folderBrowserDialog1.SelectedPath;
                    //int len = foldername.Length;
                    len = len + 1;
                    count = 0;
                    j = 0;
                    foreach (string f in Directory.GetFiles(foldername))
                    {

                        string result = f.Remove(0, len);
                        if (result.EndsWith(".jpg") || result.EndsWith(".JPG"))
                        {

                            stx[j] = f;
                            j++;
                            count++;


                            this.listBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(result));
                            //System.IO.Path.GetFileNameWithoutExtension(FileName)


                        }
                    }
                }
                else if (comboBox1.Text == "PNG ITEMS")
                {
                    listBox1.Items.Clear();
                    //string foldername = this.folderBrowserDialog1.SelectedPath;
                    //int len = foldername.Length;
                    len = len + 1;
                    count = 0;
                    j = 0;
                    foreach (string f in Directory.GetFiles(foldername))
                    {

                        string result1 = f.Remove(0, len);
                        if (result1.EndsWith(".png") || result1.EndsWith(".PNG"))
                        {

                            stx[j] = f;
                            j++;
                            count++;


                            this.listBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(result1));
                            //System.IO.Path.GetFileNameWithoutExtension(FileName)


                        }
                    }
                }
                else if (comboBox1.Text == "BMP ITEMS")
                {

                    listBox1.Items.Clear();
                    //string foldername = this.folderBrowserDialog1.SelectedPath;
                    //int len = foldername.Length;
                    len = len + 1;
                    count = 0;
                    j = 0;
                    foreach (string f in Directory.GetFiles(foldername))
                    {

                        string result1 = f.Remove(0, len);
                        if (result1.EndsWith(".bmp") || result1.EndsWith(".BMP"))
                        {

                            stx[j] = f;
                            j++;
                            count++;


                            this.listBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(result1));
                            //System.IO.Path.GetFileNameWithoutExtension(FileName)


                        }
                    }
                }

                else if (comboBox1.Text == "GIF ITEMS")
                {
                    listBox1.Items.Clear();

                    //string foldername = this.folderBrowserDialog1.SelectedPath;
                    //int len = foldername.Length;
                    len = len + 1;
                    count = 0;
                    j = 0;
                    foreach (string f in Directory.GetFiles(foldername))
                    {

                        string result = f.Remove(0, len);
                        if (result.EndsWith(".gif") || result.EndsWith(".GIF"))
                        {

                            stx[j] = f;
                            j++;
                            count++;


                            this.listBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(result));
                            //System.IO.Path.GetFileNameWithoutExtension(FileName)


                        }
                    }
                }

                else if (comboBox1.Text == "JPEG ITEMS")
                {
                    listBox1.Items.Clear();

                    //string foldername = this.folderBrowserDialog1.SelectedPath;
                    //int len = foldername.Length;
                    len = len + 1;
                    count = 0;
                    j = 0;
                    foreach (string f in Directory.GetFiles(foldername))
                    {

                        string result = f.Remove(0, len);
                        if (result.EndsWith(".jpeg") || result.EndsWith(".JPEG"))
                        {

                            stx[j] = f;
                            j++;
                            count++;


                            this.listBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(result));
                            //System.IO.Path.GetFileNameWithoutExtension(FileName)


                        }
                    }
                }

                else if (comboBox1.Text == "ICO ITEMS")
                {
                    listBox1.Items.Clear();

                    //string foldername = this.folderBrowserDialog1.SelectedPath;
                    //int len = foldername.Length;
                    len = len + 1;
                    count = 0;
                    j = 0;
                    foreach (string f in Directory.GetFiles(foldername))
                    {

                        string result = f.Remove(0, len);
                        if (result.EndsWith(".ico") || result.EndsWith(".ICO"))
                        {

                            stx[j] = f;
                            j++;
                            count++;


                            this.listBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(result));
                            //System.IO.Path.GetFileNameWithoutExtension(FileName)


                        }
                    }
                }
                button2.Enabled = false;
            
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (textBox1.Text != null)
                button2.Enabled = true;

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
            if (comboBox1.Text == "JPG ITEMS")
            {
                listBox1.Items.Clear();

                string foldername = this.folderBrowserDialog1.SelectedPath;
                int len = foldername.Length;
                len = len + 1;
                count = 0;
                j = 0;
                foreach (string f in Directory.GetFiles(foldername))
                {

                    string result = f.Remove(0, len);
                    if (result.EndsWith(".jpg") || result.EndsWith(".JPG"))
                    {
                        
                        stx[j] = f;
                        j++;
                        count++;


                        this.listBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(result));
                        //System.IO.Path.GetFileNameWithoutExtension(FileName)


                    }
                }
            }
            else if (comboBox1.Text == "PNG ITEMS")
            {
                listBox1.Items.Clear();
                string foldername = this.folderBrowserDialog1.SelectedPath;
                int len = foldername.Length;
                len = len + 1;
                count = 0;
                j = 0;
                foreach (string f in Directory.GetFiles(foldername))
                {
                    
                    string result1 = f.Remove(0, len);
                    if (result1.EndsWith(".png") || result1.EndsWith(".PNG"))
                    {
                        
                        stx[j] = f;
                        j++;
                        count++;


                        this.listBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(result1));
                        //System.IO.Path.GetFileNameWithoutExtension(FileName)


                    }
                }
            }
            else if (comboBox1.Text == "BMP ITEMS")
            {

                listBox1.Items.Clear();
                string foldername = this.folderBrowserDialog1.SelectedPath;
                int len = foldername.Length;
                len = len + 1;
                count = 0;
                j = 0;
                foreach (string f in Directory.GetFiles(foldername))
                {

                    string result1 = f.Remove(0, len);
                    if (result1.EndsWith(".bmp") || result1.EndsWith(".BMP"))
                    {
                       
                        stx[j] = f;
                        j++;
                        count++;


                        this.listBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(result1));
                        //System.IO.Path.GetFileNameWithoutExtension(FileName)


                    }
                }
            }

            else if (comboBox1.Text == "GIF ITEMS")
            {
                listBox1.Items.Clear();

                string foldername = this.folderBrowserDialog1.SelectedPath;
                int len = foldername.Length;
                len = len + 1;
                count = 0;
                j = 0;
                foreach (string f in Directory.GetFiles(foldername))
                {

                    string result = f.Remove(0, len);
                    if (result.EndsWith(".gif") || result.EndsWith(".GIF"))
                    {

                        stx[j] = f;
                        j++;
                        count++;


                        this.listBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(result));
                        //System.IO.Path.GetFileNameWithoutExtension(FileName)


                    }
                }
            }

            else if (comboBox1.Text == "JPEG ITEMS")
            {
                listBox1.Items.Clear();

                string foldername = this.folderBrowserDialog1.SelectedPath;
                int len = foldername.Length;
                len = len + 1;
                count = 0;
                j = 0;
                foreach (string f in Directory.GetFiles(foldername))
                {

                    string result = f.Remove(0, len);
                    if (result.EndsWith(".jpeg") || result.EndsWith(".JPEG"))
                    {

                        stx[j] = f;
                        j++;
                        count++;


                        this.listBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(result));
                        //System.IO.Path.GetFileNameWithoutExtension(FileName)


                    }
                }
            }

            else if (comboBox1.Text == "ICO ITEMS")
            {
                listBox1.Items.Clear();

                string foldername = this.folderBrowserDialog1.SelectedPath;
                int len = foldername.Length;
                len = len + 1;
                count = 0;
                j = 0;
                foreach (string f in Directory.GetFiles(foldername))
                {

                    string result = f.Remove(0, len);
                    if (result.EndsWith(".ico") || result.EndsWith(".ICO"))
                    {

                        stx[j] = f;
                        j++;
                        count++;


                        this.listBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(result));
                        //System.IO.Path.GetFileNameWithoutExtension(FileName)


                    }
                }
            }
            
        }

        private void listBox1_SelectedValueChanged(object sender, EventArgs e)
        {
            //nothing in here
        }

        private void button3_Click(object sender, EventArgs e)
        {
            
            timer1.Enabled = true;
            timer1.Interval = 1000;
            
            comboBox1.Visible = false;
            label3.Visible = false;
            listBox1.Items.Clear();

            string foldername = this.folderBrowserDialog1.SelectedPath;
            int len = foldername.Length;
            len = len + 1;
            j = 0;
            count = 0;


            foreach (string f in Directory.GetFiles(foldername))
            {

                string result1 = f.Remove(0, len);
                if (result1.EndsWith(".jpg") || result1.EndsWith(".JPG") || result1.EndsWith(".png") || result1.EndsWith(".PNG") || result1.EndsWith(".bmp") || result1.EndsWith(".BMP") || result1.EndsWith(".ico") || result1.EndsWith(".ICO") || result1.EndsWith(".gif") || result1.EndsWith(".GIF") || result1.EndsWith(".jpeg") || result1.EndsWith(".JPEG"))
                {

                    stx[j] = f;

                    count++;
                    //MessageBox.Show(stx[j]);
                    j++;


                    this.listBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(result1));
                    //System.IO.Path.GetFileNameWithoutExtension(FileName)


                }

            }
            j = 0;
            


        }

        private void button4_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            comboBox1.Visible = true;
            label3.Visible = true;
           
        }
       
        
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (stx[j] != null)
            {
                pictureBox1.Image = Image.FromFile(stx[j]);
                j++;
            }
            else if (stx[j] == null)
            {
                timer1.Enabled = false;

            }


        }

        private void button5_Click(object sender, EventArgs e)
        {
            MessageBox.Show("STEP 1: Press BROWSE button to browse to the folder where\n your image is present\n\nSTEP2: Press SHOW CONTENTS to show the contents of the folder of image types (.jpg,.png,.bmp,.gif,.ico,.jpeg)\n\nSTEP 3: Scroll down the list to preview the images\n-------FOR SLIDESHOW press START button------","HELP");

        }

        private void button6_Click(object sender, EventArgs e)
        {
            MessageBox.Show("DEVELOPED AND PROGRAMMED by HIMESH KUMAR\n\n MICROSOFT CODEPLEX\n\n LICENSED (MS-PL)","ABOUT US");
        }
            
           
    
    }

    }
    

